<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <Top ref="top"/>
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="审计单位">
              <j-select-depart
                v-model="queryParam.remid"
                :trigger-change="true"
                custom-return-field="id"
                :multi="false"
              />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="被审计单位">
              <j-select-depart
                v-model="queryParam.unitUnderAudit"
                :trigger-change="true"
                custom-return-field="id"
                :multi="false"
              />
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="计划年度">
              <!--              <j-date v-model='queryParam.planYear' style='width:100%'></j-date>-->
              <a-date-picker
                v-model="queryParam.planYear"
                mode="year"
                placeholder="请选择年份"
                format="YYYY"
                value-format="yyyy-MM-dd"
                :open="yearPickShow"
                style="width: 100%"
                @panelChange="handlePanelChange"
                @openChange="handleOpenChange"
              />
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :md="6" :sm="8">
              <a-form-item label="计划状态">
                <j-dict-select-tag
                  v-model="queryParam.status"
                  style="width: 100%"
                  placeholder="请选择"
                  dict-code="sj_plan_status"
                />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="计划编号">
                <a-input v-model="queryParam.number" placeholder="请输入"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="8">
              <a-form-item label="计划名称">
                <a-input v-model="queryParam.name" placeholder="请输入"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" style="margin-left: 8px" @click="searchReset">清除条件</a-button>
              <a style="margin-left: 8px" @click="handleToggleSearch">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        row-key="id"
        :columns="columns"
        :data-source="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="actionName">
          <a-button size="small" type="primary" icon="plus" @click="handleAdd('年度审计计划制定-新增')">新增</a-button>
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleCheck(record,'年度审计计划制定-查看')">查看</a>
          <span>
            <span
              v-if="(record.status == '1' && record.upstate == '1')  || (record.status == '3' && record.upstate != '2') || (record.status == '4' && record.upstate != '2') || (record.status == '5' && record.upstate != '2')"
            >
              <a-divider type="vertical"/>
              <a @click="handleEdit(record,'年度审计计划制定-编辑')">编辑</a>
            </span>
            <span v-if="record.status == '1'">
              <a-divider type="vertical"/>
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                <a>删除</a>
              </a-popconfirm>
            </span>
          </span>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->
    <CheckAndEditModel ref="modalForm" @ok="updateProList"/>
  </a-card>
</template>

<script>

  import {JeecgListMixin} from '@/mixins/JeecgListMixin'
  import Top from '../../components/Top'
  import CheckAndEditModel from './CheckAndEditModel'
  import columns from './indexColumns'
  import moment from 'moment'
  import 'moment/locale/zh-cn'
  import {httpAction, getAction} from '@/api/manage'
  import { currentY } from '@/mixins/commontime'

  export default {
    name: 'Ndsjjhzd',
    components: {
      Top,
      CheckAndEditModel
    },
    mixins: [JeecgListMixin],
    data() {
      return {
        queryParam: {
          planYear: currentY()
        },
        superParam: {
          type: '1'
        },
        // 表头
        columns: columns(this),
        url: {
          list: '/sjzyzhgl/sjPlanInfo/planInfoList',
          top: '/sjzyzhgl/sjPlanInfo/planProjectNum',
          delete: '/sjzyzhgl/sjPlanInfo/delete'
        },
        yearPickShow: false
      }
    },
    computed: {},
    created() {
      if (this.$route.params && this.$route.params.unitUnderAudit) {
        this.queryParam.remid = this.$route.params.unitUnderAudit
        this.queryParam.planYear = ''
      }
      this.getTop()
    },
    methods: {
      // 弹出日历和关闭日历的回调
      handleOpenChange(status) {
        this.yearPickShow = status
        if(this.queryParam.planYear){
          this.queryParam.planYear = moment(this.queryParam.planYear.slice(0, 4)).format('YYYY')
        }
      },
      moment,
      // 得到年份选择器的值
      handlePanelChange(value) {
        this.yearPickShow = false
        this.queryParam.planYear = moment(value).format('YYYY')
      },
      // 头部信息
      getTop() {
        getAction(this.url.top, Object.assign({}, this.superParam, this.queryParam)).then((res) => {
          if (res.success) {
            this.$refs.top.l1 = res.result[0].currYearCount
            this.$refs.top.l2 = res.result[0].changePlanCount
            this.$refs.top.l3 = res.result[0].sumCount
            this.$refs.top.r1 = res.result[0].allCount
            this.$refs.top.r2 = res.result[0].complateRate
            this.$refs.top.r3 = res.result[0].toPerform
            this.$refs.top.r4 = res.result[0].isPerform
            this.$refs.top.r5 = res.result[0].completes
          }
        }).finally(() => {
        })
      },
      updateProList() {
        this.loadData()
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
